# AcLineStatus[0](int):AC=1, DC=0 AcLineStatus[1](int):BatteryLifePercent #########################
def acLineStatus():
    import ctypes
    from ctypes import wintypes

    class SYSTEM_POWER_STATUS(ctypes.Structure):
        _fields_ = [
            ('ACLineStatus', wintypes.BYTE),
            ('BatteryFlag', wintypes.BYTE),
            ('BatteryLifePercent', wintypes.BYTE),
            ('Reserved1', wintypes.BYTE),
            ('BatteryLifeTime', wintypes.DWORD),
            ('BatteryFullLifeTime', wintypes.DWORD),
        ]

    SYSTEM_POWER_STATUS_P = ctypes.POINTER(SYSTEM_POWER_STATUS)

    GetSystemPowerStatus = ctypes.windll.kernel32.GetSystemPowerStatus
    GetSystemPowerStatus.argtypes = [SYSTEM_POWER_STATUS_P]
    GetSystemPowerStatus.restype = wintypes.BOOL

    status = SYSTEM_POWER_STATUS()
    if not GetSystemPowerStatus(ctypes.pointer(status)):
        raise ctypes.WinError()
    print('ACLineStatus', status.ACLineStatus)
    print('BatteryFlag', status.BatteryFlag)
    print('BatteryLifePercent', status.BatteryLifePercent)
    print('Reserved1', status.Reserved1)
    print('BatteryLifeTime', status.BatteryLifeTime)
    print('BatteryFullLifeTime', status.BatteryFullLifeTime)
    # 返回 AC状态 和 电池电量
    return status.ACLineStatus, status.BatteryLifePercent

acLineStatus()